<template>
  <div>
    <div>
      <div v-if="courseList.length==0" style="height: 50px;color: gray">
        <span>您还没有学习课程哦！</span>
      </div>
      <div v-else class="my_course_div" v-for="item in courseList" :key="item.courseId">
        <div class="el-col-6 course_image_div di">
          <el-image
            style="width: 100%;height: 100%"
            :src="item.imageUrl"
            fit="contain">
          </el-image>
        </div>
        <div class="el-col-18 course_detail_div di">
          <div class="course_title">
            <span>{{item.title}}</span>
          </div>
          <div class="course_detail">
            <div class="di" style="color: red">
              <span>已学</span>
              <span>{{item.studySize/item.sectionSize*100}}%</span>
            </div>
            <div class="di" style="margin-left: 50px">
              <span>学习至</span>
              <span>{{item.sectionName}}</span>
            </div>
          </div>
          <div style="height: 33px;line-height: 33px">
            <div class="di">
              <span>笔记</span>
              <span class="showSize">{{item.noteSize}}</span>
            </div>
            <div class="di" style="margin-left:50px">
              <span>问题</span>
              <span  class="showSize">{{item.questionSize}}</span>
            </div>
            <div class="di" style="float: right">
              <el-button type="success" size="small" @click="toLearn(item.sectionId, item.courseId)">
                继续学习
              </el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: 'MyCourse',
  data () {
    return {
      courseList: []
    }
  },
  computed: mapState({
    user: 'user'
  }),
  mounted () {
    this.getListCourse()
  },
  methods: {
    getListCourse () {
      var _this = this
      this.$axios.post('/api/study/getStudyCourse',
        this.$qs.stringify({
          userId: this.user.userId
        })
      ).then(function (response) {
        var data = response.data
        if (data.isSuccess) {
          _this.courseList = data.result
        }
      })
    },
    toLearn (sectionId, courseId) {
      this.$router.push(
        {path: '/video',
          query: {
            sectionId: sectionId,
            courseId: courseId,
            path: this.$route.fullPath
          }
        }
      )
    }
  }
}
</script>

<style scoped>
  .di{
    display: inline-block;
  }
  .showSize{
    color: gray;
  }
   .my_course_div{
    padding: 5px;
    height: 120px;
    width: 100%;
     margin-bottom: 10px;
  }
  .my_course_div .course_image_div {
    width: 180px;
    height: 120px;
    overflow: hidden
  }
  .my_course_div  .course_detail_div{
    height:120px;
    text-align: left;
    padding-left: 20px;
    border-bottom: 1px solid #DCDFE6;
  }
  .my_course_div .course_title{
    padding: 5px 0px;
    font-size: 20px;
    font-weight: bolder;
  }
  .my_course_div .course_detail{
    font-size: 15px;
    color: #787d82;
    margin-bottom: 20px;
  }
  .my_course_div .course_divider{
    position: relative;
  }
</style>
